// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/base/api/DeviceListApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/base/model/DeviceQueryReq'
import SubmitClass from '@api/base/model/SyncDevicesReq'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  validParam(param) {
    return !CORE.isEmpty(param.statusArray)
  },
  async getList(param, TIP = '查询设备列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryDeviceList', DTO)
    return [resp.comQuery.totalCount, resp.content || [], resp.deviceStatusCountDto || {}]
  },
  dealList([obj], { state: { MAP } }) {
    if (MAP.COUNT) MAP.COUNT = obj || {}
  },

  // —————————————————————————————— 提交 —————————————————————————————— //

  async submit(one, TIP = '同步设备') {
    const DTO = CORE.grpcDTO(SubmitClass, one)
    const resp = await CORE.grpc(TIP, CLIENT, 'syncDevices', DTO)
    return [resp.addNumber, resp.updateNumber]
  },
}
